package com.example.za.account.activity;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;

import com.example.za.account.R;
import com.example.za.account.utils.Constant;

import cn.bmob.v3.BmobUser;

public class SplashActivity extends Activity {

    private Handler handler = new Handler();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        final Intent intent = new Intent();
        BmobUser bmobUser = BmobUser.getCurrentUser();
        if (bmobUser != null) {
            //当前用户登录过，系统有缓存，设置跳转页面为主界面
            intent.setClass(this, MainActivity.class);
        } else {
            //当前用户未登录，设置跳转页面为登录页
            intent.setClass(this, LoginActivity.class);
        }
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //开启新的界面
                startActivity(intent);
                //添加渐变的过渡动画
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                //结束当前启动项
                finish();

            }
        }, Constant.DELAY_TIME);

    }


}
